html: 使用<select> <option>
...<option> </select>
放入選項,並給予value,提交type為submit。
<label for="drink">choose drink:</label>
<select name="drink" id="drink">
<option value="1">tea</option>
<option value="2">milk</option>
<option value="3">coffee</option>
<option value="4">sangria</option>
<option value="5">beer</option>
</select>
<input type="submit" name="send" value="送出">
php取得表單資料: 給予每個選項value後,可以利用value來做switch-case來執行結果。
<?php
$result="";
if(isset($_POST["send"])){
$result = $_POST["drink"];
switch($result){
case 1:
$result = "tea";
break;
case 2:
$result = "milk";
break;
case 3:
$result = "coffee";
break;
case 4:
$result = "sangria";
break;
case 5:
$result = "beer";
break;
}
echo "$result";
}
?>
輸出: